//
//  ConnotationViewController.m
//  Connotation
//
//  Created by LZXuan on 15-4-7.
//  Copyright (c) 2015年 LZXuan. All rights reserved.
//

#import "ConnotationViewController.h"
#import "BaseViewController.h"


@interface ConnotationViewController ()

@end

@implementation ConnotationViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self creatViewControllers];
}

#pragma mark - 创建子视图控制器
- (void)creatViewControllers {
    //创建子视图控制器  每个标签对应一个导航 导航里面有一个子视图控制器
    NSArray *imageTitles = @[@"圣斗士",@"海贼王",@"火影忍者",@"美女"];
    NSArray *titles = @[@"段子",@"趣图",@"视频",@"美女"];
    NSArray *viewControllerNames = @[@"JokesViewController",@"PicsViewController",@"VideosViewController",@"GirlsViewController"];
    //分类
    NSArray *categorys = @[kJokes,kPics,kVideos,kGirls];
    
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    
    //用循环创建 不同的子类对象
    for (NSInteger i = 0; i < imageTitles.count; i++) {
        //转化为 Class 类型
        Class className = NSClassFromString(viewControllerNames[i]);
        //Class 类型 可以 直接 类的操作 比如创建对象
        
        BaseViewController *baseVC = [[className alloc] init];
        
        //正向传值 传入分类
        baseVC.category = categorys[i];
        
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:baseVC];
        //标题 可以同时 对导航 和标签栏进行设置标题
        baseVC.title = titles[i];

        [baseVC release];
        //设置标签图片
        nav.tabBarItem.image = [[UIImage imageNamed:imageTitles[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        //选中图片
        nav.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageTitles[i]]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        //修改tabbaritem的选中颜色
        UIColor *titleHighlightedColor = [UIColor colorWithRed:49/255.0 green:43/255.0 blue:160/255.0 alpha:1.0];
        [nav.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                           titleHighlightedColor, UITextAttributeTextColor,
                                                           nil] forState:UIControlStateSelected];
        [arr addObject:nav];
        [nav release];
    }
    
    self.viewControllers = arr;
    [arr release];
}
- (BOOL)shouldAutorotate {
    //代码设置 界面屏幕旋转 这个方法必须写在 window的根视图控制器 /或者 是window 的根视图控制器模态(present)出来的 类中才有效，否则 代码无效
    
    return YES;
}
//设置 当前界面 支持旋转的方向
- (NSUInteger)supportedInterfaceOrientations {
    //竖直方向
    return UIInterfaceOrientationMaskPortrait;
    
    //return UIInterfaceOrientationMaskPortrait;
    /*
     UIInterfaceOrientationMaskLandscapeLeft 左旋转
     UIInterfaceOrientationMaskLandscapeRight 右旋转
     UIInterfaceOrientationMaskAll 所有方向（要和plist文件 一起设置）
     UIInterfaceOrientationMaskAllButUpsideDown (除了向下 其他方向支持)
     */
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
